<?php

require_once 'Zend/View/Helper/Abstract.php';

class Core_View_Helper_Admin_CheckSkinStyles extends Zend_View_Helper_Abstract
{
    public $partialFile = 'design/listSkin.phtml';

    /**
     *
     */
    public function checkSkinStyles($name, $values)
    {
        $config = Zend_Registry::get('config');
        $basePath = $config->design->pathToSkins;
        $xhtml = array();
        $this->view->name = $name;
        $this->view->selectedStyles = $values;

        //load the skin folders
        if (is_dir('./' . $basePath)) {
            $folders = Core_Filesystem_Dir::getDirectories('./' . $basePath);
            if (count($folders) > 0) {
                foreach ($folders as $folder) {
                    $this->view->skin = $folder;
                    $styles = Core_Filesystem_File::getFilesByType('./' . $basePath . '/' . $folder . '/styles', 'css');
                    if (is_array($styles)) {
                        foreach ($styles  as $style) {
                            //add each style sheet to the hash
                            // key = path / value = filename
                            $hashStyles[$style] = $style;
                        }
                        $this->view->styles = $hashStyles;
                        $xhtml[] = $this->view->render($this->partialFile);
                        unset($hashStyles);
                    }
                }
            }
        } else {
            require_once 'Core/View/Exception.php';
            throw new Core_View_Exception($this->view->getTranslation('Unable to locate skin folder'));
        }
        return implode(null, $xhtml);
    }
}